package org.devocean.groupbuying.service.impl;

import java.util.List;

import org.devocean.groupbuying.dao.CommentDAO;
import org.devocean.groupbuying.domain.Customer;
import org.devocean.groupbuying.domain.Comment;
import org.devocean.groupbuying.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class CommentServiceImpl implements CommentService {

	@Autowired
	private CommentDAO commentDAO;

	@Transactional(readOnly = true)
	public Comment getCommentById(Integer id) {

		return commentDAO.findCommentById(id);
	}

	@Transactional
	public Comment addOrUpdateComment(Comment comment) {
		if (comment.getCommentID() == null) {
			return commentDAO.saveComment(comment);
		} else {
			return commentDAO.updateComment(comment);
		}
	}

	@Transactional
	public void removeComment(Integer id) {
		commentDAO.deleteComment(id);

	}

	@Transactional
	public long countComments() {
		return commentDAO.countComment();
	}

	@Transactional
	public List<Comment> getAllComments() {
		return commentDAO.findAllComments();
	}

	@Transactional
	public List<Comment> CommentsByCustomer(Integer customerID) {
		return commentDAO.findCommentsByCustomer(customerID);
	}

	public Long countCommentByCustomer(Customer customer) {

		return commentDAO.countCommentByCustomer(customer.getCustomerID());
	}
}
